/////////////////////////////////////////////////////////////////////////////
/// @file BiTree_TestSuite.cpp
/// @ingroup
///
/// File containing the implementation for testing BiTree class implementation
/// Unit under test: BiTree.hpp
///
/// @see BiTree_TestSuite.hpp
///
/// @if REVISION_HISTORY_INCLUDED
/// @par Edit History
/// @li [0]   zhalat 20-Jul-2014 Initial revision of file.
/// @endif
///
/// @par &copy;  2014 HalSoft
/////////////////////////////////////////////////////////////////////////////

// SYSTEM INCLUDES

// C++ PROJECT INCLUDES
#include "BiTree_TestSuite.hpp"

using namespace tree;

CppUnit::Test* BiTree_TestSuite::suite(){
    CppUnit::TestSuite* suiteOfTests = new CppUnit::TestSuite("BiTree_TestSuite");
    //tree's element is in-build type
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_constructor1_emb", &BiTree_TestSuite::test_constructor1_emb));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_ins_left_emb", &BiTree_TestSuite::test_ins_left_emb));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_ins_right_emb", &BiTree_TestSuite::test_ins_right_emb));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_load_from_file_emb", &BiTree_TestSuite::test_load_from_file_emb));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_rem_left_emb", &BiTree_TestSuite::test_rem_left_emb));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_rem_right_emb", &BiTree_TestSuite::test_rem_right_emb));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_if_child_left_null_emb", &BiTree_TestSuite::test_if_child_left_null_emb));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_if_child_right_null_emb", &BiTree_TestSuite::test_if_child_right_null_emb));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_tree_high_emb", &BiTree_TestSuite::test_tree_high_emb));

    //tree's element is user defined class
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_constructor1_usr", &BiTree_TestSuite::test_constructor1_usr));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_ins_left_usr", &BiTree_TestSuite::test_ins_left_usr));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_ins_right_usr", &BiTree_TestSuite::test_ins_right_usr));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_load_from_file_usr", &BiTree_TestSuite::test_load_from_file_usr));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_rem_left_usr", &BiTree_TestSuite::test_rem_left_usr));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_rem_right_usr", &BiTree_TestSuite::test_rem_right_usr));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_rem_left_usr", &BiTree_TestSuite::test_if_child_left_null_usr));
    suiteOfTests->addTest(new CppUnit::TestCaller<BiTree_TestSuite>("test_rem_right_usr", &BiTree_TestSuite::test_if_child_right_null_usr));

    return suiteOfTests;
}

//***************************************************************************
// Testing default constructor
//***************************************************************************
void BiTree_TestSuite::test_constructor1_emb(void){

    //check initialization data
    CPPUNIT_ASSERT( 0==emb_bt->msize && NULL==emb_bt->pRoot && NULL==emb_bt->plast );
}

//***************************************************************************
// Testing method: ins_left()
//***************************************************************************
void BiTree_TestSuite::test_ins_left_emb(void){

    BTNode<int>* temp1;
    //creating new tree. Null means the new tree. Returned pointer is a root of the tree.
    temp1 = emb_bt->ins_left( NULL, 0 );
    CPPUNIT_ASSERT( NULL != temp1 );
    CPPUNIT_ASSERT( NULL == temp1->pup );
    CPPUNIT_ASSERT( temp1==emb_bt->biroot() );
    CPPUNIT_ASSERT( temp1==emb_bt->plast );
    //try once-again put as first element into the previous tree-it's forbidden
    CPPUNIT_ASSERT( NULL==emb_bt->ins_left( NULL, 0 ) );
    //check tree's size at this point
    CPPUNIT_ASSERT( 1==emb_bt->size() );
    //put data as left child of root
    temp1 = emb_bt->ins_left( temp1, 10 );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( 0 == temp1->pup->data );
    CPPUNIT_ASSERT( 2 == emb_bt->size() );
    //put data as left child
    temp1 = emb_bt->ins_left( temp1, 100 );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( 10 == temp1->pup->data );
    CPPUNIT_ASSERT( 3 == emb_bt->size() );
    //put data as left child
    temp1 = emb_bt->ins_left( temp1, 1000 );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( 100 == temp1->pup->data );
    CPPUNIT_ASSERT( 4 == emb_bt->size() );
    //at this point tree shall looks like:
    /*
     *   0   10 -
     *  10  100 -
     * 100 1000 -
     *1000    - -
     */
    temp1 = emb_bt->pRoot;
    CPPUNIT_ASSERT( 0 == temp1->data && NULL == temp1->pRight && NULL != temp1->pLeft );
    temp1 = temp1->pLeft;
    CPPUNIT_ASSERT( 10 == temp1->data && NULL == temp1->pRight && NULL != temp1->pLeft );
    temp1 = temp1->pLeft;
    CPPUNIT_ASSERT( 100 == temp1->data && NULL == temp1->pRight && NULL != temp1->pLeft );
    temp1 = temp1->pLeft;
    CPPUNIT_ASSERT( 1000 == temp1->data && NULL == temp1->pRight && NULL == temp1->pLeft );
}

//***************************************************************************
// Testing method: ins_right()
//***************************************************************************
void BiTree_TestSuite::test_ins_right_emb(void){

    BTNode<int>* temp1;
    //creating new tree. Null means the new tree. Returned pointer is a root of the tree.
    temp1 = emb_bt->ins_right( NULL, 0 );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( NULL == temp1->pup );
    CPPUNIT_ASSERT( temp1 == emb_bt->biroot() );
    CPPUNIT_ASSERT( temp1 == emb_bt->plast );
    //try once-again put as first element into the previous tree-it's forbidden
    CPPUNIT_ASSERT( NULL == emb_bt->ins_right( NULL, 0 ) );
    //check tree's size at this point
    CPPUNIT_ASSERT( 1 == emb_bt->size() );
    //put data as right child of root
    temp1 = emb_bt->ins_right( temp1, 9 );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( 0 == temp1->pup->data );
    CPPUNIT_ASSERT( 2 == emb_bt->size() );
    //put data as right child of root
    temp1 = emb_bt->ins_right( temp1, 99 );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( 9 == temp1->pup->data );
    CPPUNIT_ASSERT( 3 == emb_bt->size() );
    //put data as right child of root
    temp1 = emb_bt->ins_right( temp1, 999 );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( 99 == temp1->pup->data );
    CPPUNIT_ASSERT( 4 == emb_bt->size() );
    //at this point tree shall looks like:
    /*
     *   0   9 -
     *   9  99 -
     *  99 999 -
     * 999   - -
     */
    temp1 = emb_bt->pRoot;
    CPPUNIT_ASSERT( 0 == temp1->data && NULL != temp1->pRight && NULL == temp1->pLeft );
    temp1 = temp1->pRight;
    CPPUNIT_ASSERT( 9 == temp1->data && NULL != temp1->pRight && NULL == temp1->pLeft );
    temp1 = temp1->pRight;
    CPPUNIT_ASSERT( 99 == temp1->data && NULL != temp1->pRight && NULL == temp1->pLeft );
    temp1 = temp1->pRight;
    CPPUNIT_ASSERT( 999 == temp1->data && NULL == temp1->pRight && NULL == temp1->pLeft );
}

//***************************************************************************
// Testing method: test_load_from_file()
//***************************************************************************
void BiTree_TestSuite::test_load_from_file_emb(void){

    bool bflag=true;

    //negative test - file: "UnitTest_BiTree/tree_exp_emb_" doesn't exists
    try{
        emb_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_emb_");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(false==bflag);

    //positive test - file: "UnitTest_BiTree/tree_exp_emb" exists
    bflag=true;
    try{
        bflag=emb_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_emb");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);

    //loaded tree shall looks like:
    /*
     * 0  1 2
     * 1  3 4
     * 2  5 -
     * 3  - -
     * 4  - -
     * 5  - -
     */
    BTNode<int>* temp1;
    temp1 = emb_bt->pRoot;
    CPPUNIT_ASSERT( 0==temp1->data );
    temp1 = emb_bt->pRoot->pLeft;
    CPPUNIT_ASSERT( 1==temp1->data );
    temp1 = emb_bt->pRoot->pRight;
    CPPUNIT_ASSERT( 2==temp1->data );
    temp1 = emb_bt->pRoot->pLeft->pLeft;
    CPPUNIT_ASSERT( 3==temp1->data );
    temp1 = emb_bt->pRoot->pLeft->pRight;
    CPPUNIT_ASSERT( 4==temp1->data );
    temp1 = emb_bt->pRoot->pRight->pLeft;
    CPPUNIT_ASSERT( 5==temp1->data );
    //NULLs
    temp1 = emb_bt->pRoot->pLeft->pLeft;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = emb_bt->pRoot->pLeft->pRight;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = emb_bt->pRoot->pRight->pLeft;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = emb_bt->pRoot->pRight;
    CPPUNIT_ASSERT( NULL!=temp1->pLeft && NULL==temp1->pRight );

    //negative test - loading to non-zero tree
    bflag = true;
    try{
        bflag=emb_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_emb");
    }
    catch(...){
        bflag = false;
    }
    CPPUNIT_ASSERT(false==bflag);
    //remove all tree and load again
    emb_bt->rem_right(NULL);

    //positive test - loading to tree which has been completely cleaned
    bflag = true;
    try{
        bflag=emb_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_emb");
    }
    catch(...){
        bflag = false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //loaded tree shall looks like:
    /*
     * 0  1 2
     * 1  3 4
     * 2  5 -
     * 3  - -
     * 4  - -
     * 5  - -
     */
    temp1 = emb_bt->pRoot;
    CPPUNIT_ASSERT( 0==temp1->data );
    temp1 = emb_bt->pRoot->pLeft;
    CPPUNIT_ASSERT( 1==temp1->data );
    temp1 = emb_bt->pRoot->pRight;
    CPPUNIT_ASSERT( 2==temp1->data );
    temp1 = emb_bt->pRoot->pLeft->pLeft;
    CPPUNIT_ASSERT( 3==temp1->data );
    temp1 = emb_bt->pRoot->pLeft->pRight;
    CPPUNIT_ASSERT( 4==temp1->data );
    temp1 = emb_bt->pRoot->pRight->pLeft;
    CPPUNIT_ASSERT( 5==temp1->data );
    //NULLs
    temp1 = emb_bt->pRoot->pLeft->pLeft;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = emb_bt->pRoot->pLeft->pRight;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = emb_bt->pRoot->pRight->pLeft;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = emb_bt->pRoot->pRight;
    CPPUNIT_ASSERT( NULL!=temp1->pLeft && NULL==temp1->pRight );
}

//***************************************************************************
// Testing method: rem_left()
//***************************************************************************
void BiTree_TestSuite::test_rem_left_emb(void){

    BTNode<int>* temp1;
    //create a tree by loading it form file:
    bool bflag=true;
    try{
        bflag=emb_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_emb");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //tree shall looks like:
    /*
     * 0  1 2
     * 1  3 4
     * 2  5 -
     * 3  - -
     * 4  - -
     * 5  - -
    */
    //try to remove nothing
    temp1 = emb_bt->biroot()->pRight;
    emb_bt->rem_right( temp1 );
    CPPUNIT_ASSERT( 6==emb_bt->size() );
    CPPUNIT_ASSERT( NULL==temp1->pRight );
    //try to remove data '5'
    emb_bt->rem_left( temp1 );
    CPPUNIT_ASSERT( 5==emb_bt->size() );
    CPPUNIT_ASSERT( NULL==temp1->pLeft );
    CPPUNIT_ASSERT( NULL==temp1->pRight );
    //now tree looks like:
    /*
     * 0  1 2
     * 1  3 4
     * 2  - -
     * 3  - -
     * 4  - -
    */
    //try to remove all left side of branch (1,3,4)
    temp1 = emb_bt->biroot();
    emb_bt->rem_left(temp1);
    //now tree looks like (thee is not normalized at now):
    /*
     * 0 - 2
     * 2 - -
    */
    CPPUNIT_ASSERT( 2==emb_bt->size() );
    CPPUNIT_ASSERT( NULL==temp1->pLeft );
    CPPUNIT_ASSERT( NULL!=temp1->pRight );
    CPPUNIT_ASSERT( NULL==temp1->pRight->pLeft );
    CPPUNIT_ASSERT( NULL==temp1->pRight->pRight );
}

//***************************************************************************
// Testing method: rem_right()
//***************************************************************************
void BiTree_TestSuite::test_rem_right_emb(void){
    BTNode<int>* temp1;
    //create a tree by loading it form file:
    bool bflag=true;
    try{
        bflag=emb_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_emb");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //tree shall looks like:
    /*
     * 0  1 2
     * 1  3 4
     * 2  5 -
     * 3  - -
     * 4  - -
     * 5  - -
    */
    //try to remove all right side of branch (2,5)
    temp1 = emb_bt->biroot();
    emb_bt->rem_right(temp1);
    //now tree looks like (thee is not normalized at now):
    /*
     * 0  1 -
     * 1  3 4
     * 3  - -
     * 4  - -
    */
    CPPUNIT_ASSERT( 4==emb_bt->size() );
    CPPUNIT_ASSERT( NULL==temp1->pRight );
    //remove all tree's elements
    emb_bt->rem_right(NULL);
    CPPUNIT_ASSERT( 0==emb_bt->size() );
}

//***************************************************************************
// Testing method: if_child_left_null()
//***************************************************************************
void BiTree_TestSuite::test_if_child_left_null_emb(void){
    BTNode<int>* temp1;
    //create a tree by loading it form file:
    bool bflag=true;
    try{
        bflag=emb_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_emb");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //tree shall looks like:
    /*
     * 0  1 2
     * 1  3 4
     * 2  5 -
     * 3  - -
     * 4  - -
     * 5  - -
    */
    //check node 0(shall not be NULL) and 5(shall be NULL)
    temp1 = emb_bt->biroot();
    CPPUNIT_ASSERT(false==emb_bt->if_child_left_null(temp1));
    temp1 = emb_bt->biroot()->pLeft->pLeft;
    CPPUNIT_ASSERT(true==emb_bt->if_child_left_null(temp1));
}

//***************************************************************************
// Testing method: if_child_right_null()
//***************************************************************************
void BiTree_TestSuite::test_if_child_right_null_emb(void){
    BTNode<int>* temp1;
    //create a tree by loading it form file:
    bool bflag=true;
    try{
        bflag=emb_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_emb");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //tree shall looks like:
    /*
     * 0  1 2
     * 1  3 4
     * 2  5 -
     * 3  - -
     * 4  - -
     * 5  - -
    */
    //check node 0(shall not be NULL) and 2(shall be NULL)
    temp1 = emb_bt->biroot();
    CPPUNIT_ASSERT(false==emb_bt->if_child_right_null(temp1));
    temp1 = emb_bt->biroot()->pRight;
    CPPUNIT_ASSERT(true==emb_bt->if_child_right_null(temp1));
}

//***************************************************************************
// Testing method: test_tree_high_emb()
//***************************************************************************
void BiTree_TestSuite::test_tree_high_emb(void){
    BTNode<int>* temp1;
    emb_bt->ins_left( NULL, 0 );
    temp1 = emb_bt->ins_right( emb_bt->pRoot, 2 );
    emb_bt->ins_left( temp1, 3 );
    temp1 = emb_bt->ins_left( emb_bt->pRoot, 1 );
    temp1 = emb_bt->ins_left( temp1, 4 );
    temp1 = emb_bt->ins_left( temp1, 5 );
    emb_bt->ins_right( temp1, 7 );
    emb_bt->ins_left( temp1, 6 );
    //tree shall looks like:
    /*
     * 0  1 2
     * 1  4 -
     * 2  3 -
     * 3  - -
     * 4  5 -
     * 5  6 7
     * 6  - -
     * 7  - -
    */
    CPPUNIT_ASSERT( 4==emb_bt->tree_high(emb_bt->pRoot) );                                //high tree form root  as a top
    CPPUNIT_ASSERT( 1==emb_bt->tree_high(emb_bt->pRoot->pRight) );                      //high subtree form '2' as a top
    CPPUNIT_ASSERT( 0==emb_bt->tree_high(emb_bt->pRoot->pRight->pLeft) );               //high subtree form '3' as a top
    CPPUNIT_ASSERT( 3==emb_bt->tree_high(emb_bt->pRoot->pLeft) );                       //high subtree form '1' as a top
    CPPUNIT_ASSERT( 2==emb_bt->tree_high(emb_bt->pRoot->pLeft->pLeft) );                   //high subtree form '4' as a top
    CPPUNIT_ASSERT( 1==emb_bt->tree_high(emb_bt->pRoot->pLeft->pLeft->pLeft) );           //high subtree form '5' as a top
    CPPUNIT_ASSERT( 0==emb_bt->tree_high(emb_bt->pRoot->pLeft->pLeft->pLeft->pRight) ); //high subtree form '7' as a top
}
//***************************************************************************
// userclass: Testing default constructor
//***************************************************************************
void BiTree_TestSuite::test_constructor1_usr(void){

    //check initialization data
    CPPUNIT_ASSERT( 0==emb_bt->msize && NULL==emb_bt->pRoot && NULL==emb_bt->plast );
}

//***************************************************************************
// userclass: Testing method: ins_left()
//***************************************************************************
void BiTree_TestSuite::test_ins_left_usr(void){

    BTNode<userclass>* temp1;
    //creating new tree. Null means the new tree. Returned pointer is a root of the tree.
    temp1 = usr_bt->ins_left( NULL, userclass("A1") );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( temp1->pup == NULL );
    CPPUNIT_ASSERT( temp1 == usr_bt->biroot() );
    CPPUNIT_ASSERT( temp1 == usr_bt->plast );
    //try once-again put as first element into the previous tree-it's forbidden
    CPPUNIT_ASSERT( NULL == usr_bt->ins_left( NULL, userclass("A1") ));
    //check tree's size at this point
    CPPUNIT_ASSERT( 1 == usr_bt->size() );
    //put data as left child of root
    temp1 = usr_bt->ins_left( temp1, userclass("B2") );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( userclass("A1") == temp1->pup->data );
    CPPUNIT_ASSERT( 2 == usr_bt->size() );
    //put data as left child of root
    temp1 = usr_bt->ins_left( temp1, userclass("C3") );
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( userclass("B2") == temp1->pup->data );
    CPPUNIT_ASSERT( 3 == usr_bt->size() );
    //put data as left child of root
    temp1 = usr_bt->ins_left( temp1, userclass("D4"));
    CPPUNIT_ASSERT( temp1 != NULL );
    CPPUNIT_ASSERT( userclass("C3") == temp1->pup->data );
    CPPUNIT_ASSERT( 4 == usr_bt->size() );
    //at this point tree shall looks like:
    /*
     *  A1   B2 -
     *  B2   C3 -
     *  C3   D4 -
     *  D4    - -
     */
    temp1 = usr_bt->pRoot;

    CPPUNIT_ASSERT( userclass("A1")==temp1->data && NULL==temp1->pRight && NULL!=temp1->pLeft );
    temp1 = temp1->pLeft;
    CPPUNIT_ASSERT( userclass("B2")==temp1->data && NULL==temp1->pRight && NULL!=temp1->pLeft );
    temp1 = temp1->pLeft;
    CPPUNIT_ASSERT( userclass("C3")==temp1->data && NULL==temp1->pRight && NULL!=temp1->pLeft );
    temp1 = temp1->pLeft;
    CPPUNIT_ASSERT( userclass("D4")==temp1->data && NULL==temp1->pRight && NULL==temp1->pLeft );
}

//***************************************************************************
// userclass: Testing method: ins_right()
//***************************************************************************
void BiTree_TestSuite::test_ins_right_usr(void){

    BTNode<userclass>* temp1;
    //creating new tree. Null means the new tree. Returned pointer is a root of the tree.
    temp1 = usr_bt->ins_right( NULL, userclass("A01") );
    CPPUNIT_ASSERT( temp1!=NULL );
    CPPUNIT_ASSERT( temp1==usr_bt->biroot() );
    CPPUNIT_ASSERT( temp1==usr_bt->plast );
    //try once-again put as first element into the previous tree-it's forbidden
    CPPUNIT_ASSERT( NULL==usr_bt->ins_right( NULL, userclass("A01") ) );
    //check tree's size at this point
    CPPUNIT_ASSERT( 1==usr_bt->size() );
    //put data as right child of root
    temp1 = usr_bt->ins_right( temp1, userclass("B02") );
    CPPUNIT_ASSERT( temp1!=NULL );
    CPPUNIT_ASSERT( 2==usr_bt->size() );
    //put data as right child of root
    temp1 = usr_bt->ins_right( temp1, userclass("C03") );
    CPPUNIT_ASSERT( temp1!=NULL );
    CPPUNIT_ASSERT( 3==usr_bt->size() );
    //put data as right child of root
    temp1 = usr_bt->ins_right( temp1, userclass("D04") );
    CPPUNIT_ASSERT( temp1!=NULL );
    CPPUNIT_ASSERT( 4==usr_bt->size() );
    //at this point tree shall looks like:
    /*
     *   A01   B02 -
     *   B02   C03 -
     *   C03   D04 -
     *   D04     - -
     */
    temp1 = usr_bt->pRoot;
    CPPUNIT_ASSERT( userclass("A01")==temp1->data && NULL!=temp1->pRight && NULL==temp1->pLeft );
    temp1 = temp1->pRight;
    CPPUNIT_ASSERT( userclass("B02")==temp1->data && NULL!=temp1->pRight && NULL==temp1->pLeft );
    temp1 = temp1->pRight;
    CPPUNIT_ASSERT( userclass("C03")==temp1->data && NULL!=temp1->pRight && NULL==temp1->pLeft );
    temp1 = temp1->pRight;
    CPPUNIT_ASSERT( userclass("D04")==temp1->data && NULL==temp1->pRight && NULL==temp1->pLeft );
}

//***************************************************************************
// userclass: Testing method: test_load_from_file()
//***************************************************************************
void BiTree_TestSuite::test_load_from_file_usr(void){

    bool bflag=true;

    //negative test - file: "tree_exp_usr_" doesn't exists
    try{
        usr_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_usr_");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(false==bflag);

    //positive test - file: "tree_exp_usr" exists
    bflag=true;
    try{
        bflag=usr_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_usr");

    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);

    //loaded tree shall looks like:
    /*
     *  6
     *  Aa Bb Cc
     *  Bb Dd Ee
     *  Cc Ff -
     *  Dd - -
     *  Ee - -
     *  Ff - -
     */
    BTNode<userclass>* temp1;
    temp1 = usr_bt->pRoot;
    CPPUNIT_ASSERT( userclass("Aa")==temp1->data );
    temp1 = usr_bt->pRoot->pLeft;
    CPPUNIT_ASSERT( userclass("Bb")==temp1->data );
    temp1 = usr_bt->pRoot->pRight;
    CPPUNIT_ASSERT( userclass("Cc")==temp1->data );
    temp1 = usr_bt->pRoot->pLeft->pLeft;
    CPPUNIT_ASSERT( userclass("Dd")==temp1->data );
    temp1 = usr_bt->pRoot->pLeft->pRight;
    CPPUNIT_ASSERT( userclass("Ee")==temp1->data );
    temp1 = usr_bt->pRoot->pRight->pLeft;
    CPPUNIT_ASSERT( userclass("Ff")==temp1->data );
    //NULLs
    temp1 = usr_bt->pRoot->pLeft->pLeft;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = usr_bt->pRoot->pLeft->pRight;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = usr_bt->pRoot->pRight->pLeft;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = usr_bt->pRoot->pRight;
    CPPUNIT_ASSERT( NULL!=temp1->pLeft && NULL==temp1->pRight );

    //negative test - loading to non-zero tree
    bflag = true;
    try{
        bflag=usr_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_usr");
    }
    catch(...){
        bflag = false;
    }
    CPPUNIT_ASSERT(false==bflag);
    //remove all tree and load again
    usr_bt->rem_right(NULL);

    //positive test - loading to tree which has been completely cleaned
    bflag = true;
    try{
        bflag=usr_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree//tree_exp_usr");
    }
    catch(...){
        bflag = false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //loaded tree shall looks like:
    /*
     *  6
     *  Aa Bb Cc
     *  Bb Dd Ee
     *  Cc Ff -
     *  Dd - -
     *  Ee - -
     *  Ff - -
     */
    temp1 = usr_bt->pRoot;
    CPPUNIT_ASSERT( userclass("Aa")==temp1->data );
    temp1 = usr_bt->pRoot->pLeft;
    CPPUNIT_ASSERT( userclass("Bb")==temp1->data );
    temp1 = usr_bt->pRoot->pRight;
    CPPUNIT_ASSERT( userclass("Cc")==temp1->data );
    temp1 = usr_bt->pRoot->pLeft->pLeft;
    CPPUNIT_ASSERT( userclass("Dd")==temp1->data );
    temp1 = usr_bt->pRoot->pLeft->pRight;
    CPPUNIT_ASSERT( userclass("Ee")==temp1->data );
    temp1 = usr_bt->pRoot->pRight->pLeft;
    CPPUNIT_ASSERT( userclass("Ff")==temp1->data );
    //NULLs
    temp1 = usr_bt->pRoot->pLeft->pLeft;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = usr_bt->pRoot->pLeft->pRight;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = usr_bt->pRoot->pRight->pLeft;
    CPPUNIT_ASSERT( NULL==temp1->pLeft && NULL==temp1->pRight );
    temp1 = usr_bt->pRoot->pRight;
    CPPUNIT_ASSERT( NULL!=temp1->pLeft && NULL==temp1->pRight );
}

//***************************************************************************
// userclass: Testing method: rem_left()
//***************************************************************************
void BiTree_TestSuite::test_rem_left_usr(void){
    BTNode<userclass>* temp1;
    //create a tree by loading it form file:
    bool bflag=false;
    try{
        bflag=usr_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree//tree_exp_usr");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true == bflag);
    //loaded tree shall looks like:
    /*
     *  Aa Bb Cc
     *  Bb Dd Ee
     *  Cc Ff -
     *  Dd -  -
     *  Ee -  -
     *  Ff -  -
     */
    //try to remove nothing
    temp1 = usr_bt->biroot()->pRight;
    usr_bt->rem_right( temp1 );
    CPPUNIT_ASSERT( 6==usr_bt->size() );
    CPPUNIT_ASSERT( NULL==temp1->pRight );
    //try to remove data 'Ff'
    usr_bt->rem_left( temp1 );
    CPPUNIT_ASSERT( 5==usr_bt->size() );
    CPPUNIT_ASSERT( NULL==temp1->pLeft );
    CPPUNIT_ASSERT( NULL==temp1->pRight );
    //now tree looks like:
    /*
     *  Aa Bb Cc
     *  Bb Dd Ee
     *  Cc Ff -
     *  Dd -  -
     *  Ee -  -
     *  Ff -  -
     */
    //try to remove all left side of branch (Bb,Dd,Ee)
    temp1 = usr_bt->biroot();
    usr_bt->rem_left(temp1);
    //now tree looks like (tree is not normalized at now):
    /*
     * Aa - Cc
     * Cc - -
    */
    CPPUNIT_ASSERT( 2==usr_bt->size() );
    CPPUNIT_ASSERT( NULL==temp1->pLeft );
    CPPUNIT_ASSERT( NULL!=temp1->pRight );
    CPPUNIT_ASSERT( NULL==temp1->pRight->pLeft );
    CPPUNIT_ASSERT( NULL==temp1->pRight->pRight );
}

//***************************************************************************
// userclass: Testing method: rem_right()
//***************************************************************************
void BiTree_TestSuite::test_rem_right_usr(void){
    BTNode<userclass>* temp1;
    //create a tree by loading it form file:
    bool bflag=true;
    try{
        bflag=usr_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_usr");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //loaded tree shall looks like:
    /*
     *  Aa Bb Cc
     *  Bb Dd Ee
     *  Cc Ff -
     *  Dd -  -
     *  Ee -  -
     *  Ff -  -
     */
    //try to remove all right side of branch (Cc,Ff)
    temp1 = usr_bt->biroot();
    usr_bt->rem_right(temp1);
    //now tree looks like (thee is not normalized at now):
    /*
     * Aa  Bb -
     * Bb  Dd Ee
     * Dd  -  -
     * Ee  -  -
    */
    CPPUNIT_ASSERT( 4==usr_bt->size() );
    CPPUNIT_ASSERT( NULL==temp1->pRight );
    //remove all tree's elements
    usr_bt->rem_right(NULL);
    CPPUNIT_ASSERT( 0==usr_bt->size() );
}

//***************************************************************************
// userclass: Testing method: if_child_left_null()
//***************************************************************************
void BiTree_TestSuite::test_if_child_left_null_usr(void){
    BTNode<userclass>* temp1;
    //create a tree by loading it form file:
    bool bflag=true;
    try{
        bflag=usr_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_usr");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //loaded tree shall looks like:
    /*
     *  Aa Bb Cc
     *  Bb Dd Ee
     *  Cc Ff -
     *  Dd -  -
     *  Ee -  -
     *  Ff -  -
     */
    //check node 0(shall not be NULL) and 5(shall be NULL)
    temp1 = usr_bt->biroot();
    CPPUNIT_ASSERT(false==usr_bt->if_child_left_null(temp1));
    temp1 = usr_bt->biroot()->pLeft->pLeft;
    CPPUNIT_ASSERT(true==usr_bt->if_child_left_null(temp1));
}

//***************************************************************************
// userclass: Testing method: if_child_right_null()
//***************************************************************************
void BiTree_TestSuite::test_if_child_right_null_usr(void){
    BTNode<userclass>* temp1;
    //create a tree by loading it form file:
    bool bflag=true;
    try{
        bflag=usr_bt->load_from_file("../Algorythm_UT/UnitTest_BiTree/tree_exp_usr");
    }
    catch(...){
        bflag=false;
    }
    CPPUNIT_ASSERT(true==bflag);
    //loaded tree shall looks like:
    /*
     *  Aa Bb Cc
     *  Bb Dd Ee
     *  Cc Ff -
     *  Dd -  -
     *  Ee -  -
     *  Ff -  -
     */
    //check node 0(shall not be NULL) and 2(shall be NULL)
    temp1 = usr_bt->biroot();
    CPPUNIT_ASSERT(false==usr_bt->if_child_right_null(temp1));
    temp1 = usr_bt->biroot()->pRight;
    CPPUNIT_ASSERT(true==usr_bt->if_child_right_null(temp1));
}
